package com.wwz.listener;

import com.wwz.config.MyTaskListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.core.annotation.Order;

@Configuration
@ConditionalOnBean(value={MyTaskListener.class})
public class PushEventListener {


    @Bean
    public MyTaskListener myTaskListener(){
        return new MyTaskListener();
    }
    @Autowired
    private MyTaskListener myTaskListener;
    @Bean
    public ApplicationEventMulticaster applicationEventMulticaster(){
        SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster();
        multicaster.addApplicationListener(myTaskListener);
        return multicaster;
    }
    @Bean
    @ConditionalOnBean(value=MyTaskListener.class)
    public SpringApplication springApplication(){
        SpringApplication s =  new SpringApplication();
        s.addListeners(myTaskListener);
        return s;
    }
}
